package main

import "time"

const (
	dateFormat = "02 Jan 06 15:04"

	lowPriority  = 0
	midPriority  = 1
	highPriority = 2
)

func dateValidator(text string) error {
	_,err := time.Parse(dateFormat, text)
	return err
}

type task struct {
	// 定义标题和描述语句
	title, description string
	// 该任务是否已经完成
	done   				bool
	category  			string
	priority 			int
	due 				*time.Time
	completion 			float64
}

// 定义任务链表的切片
type taskList struct {
	tasks []*task
}

// 添加任务，新添加的任务放到列表头
func (l *taskList) add(t *task) {
	// 使用t初始化一个一样的切片，并将原有的切片添加到后面
	l.tasks = append([]*task{t}, l.tasks...)
}

/* 获取剩余没有完成的任务列表 */
func (l *taskList) remaining() []*task {
	var items []*task
	for _, task := range l.tasks {
		if !task.done {
			items = append(items, task)
		}
	}
	return items
}

/* 获取已经完成的任务列表 */
func (l *taskList) done() []*task {
	var items []*task
	for _, task := range l.tasks {
		if task.done {
			items = append(items, task)
		}
	}
	return items
}

func dummyData() *taskList {
	return &taskList{
		tasks: []*task{
			{title: "Nearly done", description: "you can tick my checkbox and I will be marked as done and disappear"},
			{title: "Functions", description: "Tap the plus icon above to add a new task, or tap the munus icon to remove this one"},
		},
	}
}
